<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="lib/jsbn.js"></script>
<script type="text/javascript" src="lib/prng4.js"></script>
<script type="text/javascript" src="lib/rng.js"></script>
<script type="text/javascript" src="lib/base64.js"></script>
<script type="text/javascript" src="lib/rsa.js"></script>
</head>
<body>

<input type="file" name="">

<script type="text/javascript">

(function(){

var MOD = 10;

function num2arr(n, a){
	a = a || [];
	if(n < MOD){
		a.push(n);
	} else {
		a.push(n % MOD);
		num2arr((n / MOD) << 0, a);
	}
	return a;
}

function arr_plus_num(a, n, i){
	i = i || 0;
	var v = (a[i] || 0) + (n || 0);
	if(v >= MOD){
		a[i] = v % MOD;
		arr_plus_num(a, (v / MOD) << 0, i + 1);
	} else {
		a[i] = v;
	}
}
function arr_plus_modnum(a, n, i){
	i = i || 0;
	var v = (a[i] || 0) + (n || 0);
	if(v >= MOD){
		a[i] = v - MOD;
		arr_plus_modnum(a, 1, i + 1);
	} else {
		a[i] = v;
	}
}
function arr_plus_arr(a, b, offset){
	offset = offset || 0;
	var i = offset;
	for(; i < a.length; i++){
		arr_plus_modnum(a, b[i - offset], i);
	}
	if(i - offset < b.length){
		for(; i < b.length + offset; i++){
			arr_plus_modnum(a, b[i - offset], i);
		}
	}
	fill_arr(a, 0);
}

function arr_minus_num(a, n, i, noTrim){
	i = i || 0;
	var v = (a[i] || 0) - (n || 0), b;
	if(v < 0 && a.length > i + 1){
		b = Math.ceil(-v / MOD);
		a[i] = v % MOD;
		if(a[i] < 0) a[i] += MOD;
		arr_minus_num(a, b, i + 1, true);
	} else {
		a[i] = v;
	}
	!noTrim && trim_arr(a);
}
function arr_minus_modnum(a, n, i){
	i = i || 0;
	if(i >= a.length) return;
	var v = (a[i] || 0) - (n || 0);
	if(v < 0){
		if(a.length > i + 1){
			a[i] = v + MOD;
			arr_minus_num(a, 1, i + 1);
		} else {
			a[i] = 0;
		}
	} else {
		a[i] = v;
	}
}
function arr_minus_arr(a, b, offset){

	if(less_than(a, b)){
		a.splice(0, a.length);
		return;
	}

	offset = offset || 0;
	var i = offset;
	for(; i < a.length; i++){
		arr_minus_modnum(a, b[i - offset], i);
	}
	if(i - offset < b.length){
		for(; i < b.length + offset; i++){
			arr_minus_modnum(a, b[i - offset], i);
		}
	}
	trim_arr(a);
}

function arr_multi_num(a, n){
	if(n <= 0){
		a.splice(a.length);
		return;
	}
	var add = 0;
	a.forEach(function(v, i, a){
		v = v * n + add;
		if(v < MOD){
			a[i] = v;
			add = 0;
		} else {
			a[i] = v % MOD;
			add = (v / MOD) << 0;
		}
	});
	if(add > 0) {
		arr_plus_num(a, add, a.length);
	}
}
function arr_multi_arr(a, b){
	var r = a.slice(0);
	a.splice(0, a.length);
	b.forEach(function(v, i){
		if(!v) return;
		var _a = r.slice(0);
		arr_multi_num(_a, v);
		arr_plus_arr(a, _a, i);
	});
	r = null;
}

function arr_divided_modnum(a, n){
	var start = a.length - 1;
	var m = a[start];
	if(m > n){
		var div = (m / n) << 0;
		var mod = (m % n);
		a[start] = div;
	} else {
		start -= 1;
		var piece = a.splice(start, a.length - start);
		console.log(piece, n);

	}
}

function arr_divided_arr(a, b){
	var c = less_than(a, b);
	if(c){
		a.splice(0, a.length);
		if(c === 2) a.push(1);
		return;
	}

	var result = [];

	var start = a.length - b.length;
	var end = a.length;
	var divBit = 1;
	var piece = a.slice(start, end);
	if(less_than(piece, b)){
		start -= 1;
		divBit += 1;
		piece = a.slice(start, end);
	}
	var last = piece[piece.length - 1];
	var lastB = b[b.length - 1];
	var div = (last / lastB) << 0;
	var _b = b.slice(0);
	arr_multi_num(_b, div);
	if(less_than(piece, _b)){
		arr_minus_arr(_b, b);
	}
	arr_minus_arr(a, _b, start);
}

function trim_arr(a){
	while(a.length){
		if(a[a.length - 1] > 0) break;
		!a[a.length - 1] ? a.pop() : a.splice(0, a.length);
	}
}

function fill_arr(a, v) {
	v = v || 0;
	var i = 0, l = a.length;
	for(; i < l; i++){
		if(typeof(a[i]) == 'undefined') a[i] = v;
	}
}

function equal_arr(a, b){
	return a.length == b.length && a.every(function(v, i){
		return b[i] === v;
	});
}

function less_than(a, b){
	if(a.length < b.length) return 1;
	else if(a.length == b.length){
		for(var i = a.length - 1; i >= 0; i--){
			if(a[i] === b[i]) continue;
			return a[i] < b[i] ? 1 : 0;
		}
		return 2;
	}
	return 0;
}

function pad_left(arr, c){
	if(!c) return;
	while(c-- > 0){
		arr.unshift(0);
	}
}


// var a = 2113;
// var b = 1911;

// var A = num2arr(a);
// var B = num2arr(b);

// arr_divided_modnum(A, 3)

// // arr_multi_num(A, b);
// // console.log(1231 * 34)

// // arr_multi_arr(A, B);

// // console.log(a * b)

// // console.log(arr_divided_arr(A, B));

// console.log(A, B);


})();

document.querySelector('input').onchange = function(){
	var file = this.files[0];
	var reader = new FileReader();
	reader.onload = function(){
		console.log(this.result);
		var data = new Uint8Array(this.result);
		crypto.subtle.digest(
			{"name": "MD5"}, data
		).then(function(ab){
			console.log(bufferToString(ab))
		});

	};
	reader.readAsArrayBuffer(file);
};

function bufferToString(b){  
	var dataview = new DataView(b);  
	result = "";  
	for (var i = 0; i < b.byteLength; i += 4) {  
		tmp = dataview.getUint32(i).toString(16);  
		result += (tmp.length == 8 ? "" : "0") + tmp;  
	}  
	return result;  
}  

var data = new Uint8Array([1,2,3,4,5,6,7,8,9])
var data = new Uint8Array([97,98,99])
var p = crypto.subtle.digest(
	{"name": "SHA-512"}, data
).then(function(ab){
	console.log(bufferToString(ab))
});
console.log(p)

</script>

</body>
</html>